package controller;

import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;

import javax.swing.JTextField;

import view.AdminContactView;
import view.HomeContact;

public class SearchKeyListener implements KeyListener {

	@Override
	public void keyPressed(KeyEvent e) {

	}

	@Override
	public void keyReleased(KeyEvent e) {
		String name = ((JTextField)e.getSource()).getName();
		String txt = ((JTextField)e.getSource()).getText();
		if (!txt.isEmpty()){
			if (txt.charAt(txt.length()-1)!=' ')
				if (name.contentEquals("admin"))
					AdminContactView.text = txt;
				else
					HomeContact.text = txt;
		} else if (name.contentEquals("admin"))
			AdminContactView.text = "";
		else
			HomeContact.text = "";
		if (name.contentEquals("admin"))
			AdminContactView.uppdater();
		else
			HomeContact.uppdater();
		((JTextField) e.getSource()).requestFocus();
	}


	@Override
	public void keyTyped(KeyEvent e) {

	}
}
